package com.nf.xiaomi.dao.impl;


import com.nf.dbutils.SqlExecutor;
import com.nf.dbutils.handlers.BeanListHandler;
import com.nf.xiaomi.dao.EmployeeDao;
import com.nf.xiaomi.entity.EmployeeEntity;
import com.nf.xiaomi.util.SqlExecutorUtils;

import java.util.List;

public class EmployeeDaoImpl implements EmployeeDao {
    SqlExecutor executor = SqlExecutorUtils.getExecutor();
    public List<EmployeeEntity> getAll() {
        String sql = "select employee_id,employee_account,employee_password,employee_name,employee_picture,employee_position,employee_phone,employee_date,nstate from employee";
        return executor.query(sql, new BeanListHandler<>(EmployeeEntity.class));
    }

    public List<EmployeeEntity> getAll(String employeeName) {
        String sql = "select employee_id,employee_account,employee_password,employee_name,employee_picture,employee_position,employee_phone,employee_date,nstate from employee " +
                "where employee_account like ? or employee_name like ?";
        return executor.query(sql, new BeanListHandler<>(EmployeeEntity.class), "%"+employeeName+"%","%"+employeeName+"%");
    }

    public Integer deleteByID(Integer employeeID) {
        String sql = "delete from employee where employee_id=?";
        return executor.update(sql, employeeID);
    }
}
